import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/goods_child_entity.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/utils/widget_generate_util.dart';
import 'package:library_base/widget/image/local_image.dart';

Widget inkBgWell({
  Color bgColor = Colors.transparent,
  GestureTapCallback? onTap,
  Decoration? decoration,
  Color splashColor = Colors.transparent,
  EdgeInsetsGeometry? padding,
  double? width,
  double? height,
  double? inkWidth,
  double? inkHeight,
  Widget? child,
}) {
  return Material(
    color: bgColor,
    child: Ink(
      width: inkWidth,
      height: inkHeight,
      decoration: decoration,
      child: InkWell(
        splashColor: splashColor,
        onTap: onTap,
        child: Container(
          width: width,
          height: height,
          padding: padding,
          child: child,
        ),
      ),
    ),
  );
}

Widget imageWithTextWorkbench(
  String image,
  String data, {
  TextCallback? onTap,
  BoxFit? fit,
  String? package
}) {
  List<Widget> widgets = [];
  widgets
      .add(LocalImage(image, package: package??Constant.packAdmin(), width: 45.w, height: 45.w, fit: fit));
  widgets.add(Gaps.vGap20);
  widgets.add(Center(
      child: Text(data, style: TextStyles.textWhite26, maxLines: 2, textAlign: TextAlign.center)));
  return inkBgWell(
    child: Column(mainAxisAlignment: MainAxisAlignment.center, children: widgets),
    onTap: () => onTap?.call(data),
    // padding: EdgeInsets.only(top: 35.w),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

Widget imageWithTextMain(String image, String data, {TextCallback? onTap}) {
  List<Widget> widgets = [];
  widgets.add(LocalImage(image, package: Constant.packCommon(), width: 124.w, height: 124.w));
  widgets.add(Gaps.vGap20);
  widgets.add(Center(
      child: Text(data, style: TextStyles.textBlack132, maxLines: 2, textAlign: TextAlign.center)));
  return inkBgWell(
    child: Column(children: widgets),
    onTap: () => onTap?.call(data),
    padding: EdgeInsets.only(top: 35.w),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

Widget textInkBgWell(
  String data, {
  TextCallback? onTap,
}) {
  return inkBgWell(
    child: Container(
        padding: GenerateWidgetUtil.pageHGap(),
        alignment: Alignment.center,
        height: double.infinity,
        child: Text(data, style: TextStyles.textSeventhColor28, textAlign: TextAlign.center)),
    onTap: () => onTap?.call(data),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

Widget columnInkBgWell<T>(
  T data, {
  Callback<T>? onTap,
  List<Widget> children = const <Widget>[],
}) {
  return inkBgWell(
    child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: children),
    onTap: () => onTap?.call(data),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

Widget rowInkBgWell<int>(
  int count, {
  Callback<int>? onTap,
}) {
  return inkBgWell(
    child: Container(
        child: Stack(fit: StackFit.passthrough, children: [
      Positioned(
        left: 24.w,
        top: 8.w,
        child: LocalImage('admin_goods_cart',
            package: Constant.packAdmin(), width: 56.w, height: 56.w),
      ),
      Positioned(
        left: 100.w,
        top: 23.w,
        child: Text('共选中$count个商品'),
      ),
    ])),
    onTap: () => onTap?.call(count),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

Widget deleteBgWell(
  GoodsChildEntity goodsChildEntity, {
  Callback<GoodsChildEntity>? onTap,
}) {
  return inkBgWell(
    child: Padding(
        padding: EdgeInsets.all(24.w),
        child:
            LocalImage('admin_delete', package: Constant.packAdmin(), width: 32.w, height: 32.w)),
    onTap: () => onTap?.call(goodsChildEntity),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

Widget filterWell(
  String stationTimeBegin,
  String stationTimeEnd, {
  Callback2<String, String>? onTap,
}) {
  return inkBgWell(
    child: Container(
        padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 24.w),
        child:
            LocalImage('admin_filter', package: Constant.packAdmin(), width: 38.w, height: 38.w)),
    onTap: () => onTap?.call(stationTimeBegin, stationTimeEnd),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

Widget batchEditWell(
  double weight,
  double serviceCharge, {
  Callback2<double, double>? onTap,
}) {
  return inkBgWell(
    child: Container(
        padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 24.w),
        child: LocalImage('common_edit', package: Constant.packLib(), width: 38.w, height: 38.w)),
    onTap: () => onTap?.call(weight, serviceCharge),
    splashColor: ThemeUtil.getTheme().colorScheme.primary.withOpacity(0.5),
  );
}

///构建按钮
Container buildTextButton(VoidCallback voidCallback,
    {margin = const EdgeInsets.all(8.0), data = '按钮'}) {
  return Container(
    margin: margin,
    width: double.infinity,
    child: TextButton(
      style: ButtonStyle(
        side: MaterialStateProperty.all(const BorderSide(color: Colors.black12, width: 1)),
        backgroundColor: MaterialStateProperty.resolveWith(((states) {
          if (states.contains(MaterialState.pressed)) {
            return Colors.grey;
          }
          return Colors.blue;
        })),
        foregroundColor: MaterialStateProperty.resolveWith(((states) {
          if (states.contains(MaterialState.pressed)) {
            return Colors.white54;
          }
          return Colors.white;
        })),
      ),
      onPressed: voidCallback,
      child: Text(data),
    ),
  );
}

typedef TextCallback = void Function(String);

typedef Callback<T> = void Function(T);

typedef Callback2<T, E> = void Function(T, E);
